"""DjangoBBS URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, re_path
from app01 import views

from django.views.static import serve   # 导入serve模块
from DjangoBBS import settings          # 导入配置文件

urlpatterns = [
    path('admin/', admin.site.urls),
    path(r'register/', views.register, name='reg'),     # 思考路由分发,分组解析
    path(r'login/', views.login, name='login'),
    path(r'get_code/', views.get_code, name='gc'),

    # 首页
    path(r'home/', views.home, name='home'),
    # 修改密码
    path(r'set_password/', views.set_password, name='set_pwd'),
    # 退出登录
    path(r'logout/', views.logout, name='logout'),

    # 点赞点踩
    path(r'up_or_down/', views.up_or_down),

    # 评论
    path(r'comment/', views.comment),

    # 暴露后端指定文件夹资源
    re_path(r'^media/(?P<path>.*)', serve, {'document_root':settings.MEDIA_ROOT}),
    # 在暴露资源的时候一定 要明确该资源是否可以暴露,否则会源码泄露

    # 后台管理
    path(r'backend/', views.backend),

    # 添加文章
    path(r'add/article/', views.add_article),

    # 编辑器上传图片接口
    path(r'upload_image/', views.upload_image),

    # 修改用户头像
    path(r'set/avatar/', views.set_avatar),

    # 删除文章
    path(r'del_article/', views.del_article),

    # 编辑文章
    path(r'edit_article/', views.edit_article),

    # 添加分类
    path(r'add_category/', views.add_category),

    # 添加标签
    path(r'add_tag/', views.add_tag),

    # 个人站点页面搭建
    re_path(r'^(?P<username>\w+)/$', views.site, name='site'),

    # 侧边栏筛选功能
    # re_path(r'(?P<username>\w+)/category/(\d+)/$', views.site, name='site'),
    # re_path(r'(?P<username>\w+)/tag/(\d+)/$', views.site, name='site'),
    # re_path(r'(?P<username>\w+)/archive/(\w+)/$', views.site, name='site'),
    # 上面的三条urL其实可以合到第一条
    re_path(r'^(?P<username>\w+)/(?P<condition>category|tag|archive)/(?P<param>.*)/$', views.site),

    # 文章详情页
    re_path(r'^(?P<username>\w+)/article/(?P<article_id>\d+)/$', views.article_detail)
]
